package cn.monkey.transport.core;

import java.util.*;

public class SimpleDelegatesExchange implements DelegatesExchange {

    protected final String id;
    protected final Collection<Exchange> delegates;

    public SimpleDelegatesExchange(String id, Collection<? extends Exchange> delegates) {
        this.id = id;
        Objects.requireNonNull(delegates);
        if (delegates.stream().anyMatch(delegate -> delegate instanceof DelegatesExchange)) {
            throw new IllegalArgumentException("delegatesExchange can not contains DelegatesExchange type");
        }
        this.delegates = Collections.unmodifiableCollection(delegates);
    }

    @Override
    public String id() {
        return this.id;
    }

    @Override
    public ExchangeContext context() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Collection<Exchange> delegates() {
        return this.delegates;
    }

}
